package com.biz.primus.ms.product.api;

import com.biz.primus.base.vo.PageResult;
import com.biz.primus.base.vo.ProductListRestVo;
import com.biz.primus.commodity.vo.frontend.ProductDetailRequestVo;
import com.biz.primus.commodity.vo.frontend.ProductDetailResult;
import com.biz.primus.commodity.vo.frontend.RecommendProductReqVo;
import com.biz.primus.ms.base.api.BaseApiController;
import com.biz.primus.ms.product.service.ProductService;
import com.biz.primus.product.vo.OrderProductInfoRespVo;
import com.biz.primus.product.vo.OrderProductReqVo;
import com.biz.primus.product.vo.SecProductInfoReqVo;
import com.biz.primus.product.vo.SecProductInfoRespVo;
import com.biz.primus.search.vo.search.SearchProductRequestVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;

@Api("商品前端接口")
@RestController
@RequestMapping("soa/frontendProductService")
public class ProductFrontendApiController extends BaseApiController {

    @Autowired
    private ProductService productService;

    @ApiOperation("批量秒杀商品详情")
    @PostMapping("secProductInfo")
    List<SecProductInfoRespVo> secProductInfo(@RequestBody SecProductInfoReqVo secProductInfoReqVo) {
        return productService.secProductInfo(secProductInfoReqVo);
    }

    @ApiOperation("单个获取秒杀商品详情")
    @GetMapping("secProductInfo")
    SecProductInfoRespVo secProductInfo(Long productId) {
        return productService.secProductInfo(new SecProductInfoReqVo(Collections.singletonList(productId))).get(0);
    }


    @ApiOperation("订单购物车商品接口")
    @PostMapping("orderProduct")
    List<OrderProductInfoRespVo> orderProduct(@RequestBody OrderProductReqVo orderProductReqVo){
        return productService.orderProduct(orderProductReqVo);
    }

    @ApiOperation("搜索商品")
    @PostMapping("searchProduct")
    PageResult<ProductListRestVo> searchProduct(@RequestBody SearchProductRequestVo reqVo){
        return productService.searchProducts(reqVo);
    }

    @ApiOperation("商品详情")
    @PostMapping("productDetail")
    ProductDetailResult productDetail(@RequestBody ProductDetailRequestVo requestVo){
        return productService.productDetail(requestVo);
    }

    @ApiOperation("指定商品集合 返回列表信息")
    @PostMapping("indexProduct")
    List<ProductListRestVo> indexProduct(@RequestBody OrderProductReqVo reqVo){
        return productService.indexProduct(reqVo);
    }

    @ApiOperation("推荐商品")
    @PostMapping("recommendProducts")
    List<ProductListRestVo> recommendProducts(@RequestBody RecommendProductReqVo reqVo){
        return productService.recommendProducts(reqVo);
    }

}
